package controller.servlet;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public class TokenStore {
	
	private static TokenStore instance = new TokenStore();
	
	private Set<String> guid = Collections.synchronizedSet(new HashSet<String>());
	
	private TokenStore() {
		
	}
	
	public static TokenStore getInstance() {
		return instance;
	}
	
	public boolean isValid(String token) {
		if(guid.contains(token)) {
			guid.remove(token);
			return true;
		}
		else
			return false;
	}
	
	public String nextGuid() {
		String token = UUID.randomUUID().toString();
		guid.add(token);
		return token;
	}

}
